#include <stdio.h>
#include <string.h>

#include "../src/util.c"    // directly include it

const char *testcases[] = {
    "abc\tabc", "abc\\tabc",
    "abc\nabc", "abc\\nabc",
    "abc\\abc", "abc\\\\abc",
    "a\nb\tc\rd\\e", "a\\nb\\tc\rd\\\\e", 
};

int main(int arg, char *argv[]) 
{
    size_t count = sizeof(testcases) / sizeof(testcases[0]);
    size_t i;

    size_t failed = 0;

    for (i = 0; i < count; i += 2) {
        gchar *ret0 = nutstore_util_sanitize(testcases[i]);
        if (strcmp(ret0, testcases[i+1]) != 0) {
            fprintf(stderr, "%d Sanitize: result \"%s\" VS expected \"%s\"\n", 
                    i/2, ret0, testcases[i+1]);
            failed++;
        }

        gchar *ret1 = nutstore_util_desanitize(ret0);
        if (strcmp(ret1, testcases[i]) != 0) {
            fprintf(stderr, "%d Desanitize: result \"%s\" VS expected \"%s\"\n", 
                i/2, ret1, testcases[i]);
            failed++;
        }

        g_free(ret0);
        g_free(ret1);
    } 

    fprintf(stderr, "Testcases %d, Passed %d, Failed %d\n", count, count, failed);
    return 0;
}

